﻿using Hicap.QRCodeWarehouse.Core.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;

namespace Hicap.QRCodeWarehouse.Core.EFCore
{
    public class WarehouseDbContextFactory : IDesignTimeDbContextFactory<WarehouseDbContext>
    {
        public WarehouseDbContext CreateDbContext(string[] args)
        {
            DbContextOptionsBuilder builder = new DbContextOptionsBuilder();
            IConfigurationRoot configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            WarehouseDbContextConfigurer.Configure(
                builder,
                configuration.GetConnectionString(SysConsts.ConnectionName)
            );

            return new WarehouseDbContext(builder.Options);
        }
    }
}